<template>
  <div v-loading="loading" element-loading-text="正在退出..." element-loading-background="rgba(0, 0, 0, 0.8)" class="layout-container">
    <!-- 左侧菜单 -->
    <div class="left-side" :style="{ width: !isCollapse ? '280px' : '60px' }">
      <div class="left-side-content">
        <div :class="['system-title', isCollapse ? 'collapse-title' : 'noCollapse-title']">
          <GsvgIcon class="system-logo" icon="logo"></GsvgIcon>
          <div class="title-text">商汤教科研大模型综合应用系统</div>
        </div>
        <!-- 对话菜单 -->
        <leftMenu :menuData="menuData" :isCollapse="isCollapse"></leftMenu>
      </div>

      <!-- 伸缩按钮 -->
      <div class="telescoping-btn" @click="telescopingClick">
        <div class="telescoping-btn-bg">
          <div class="telescoping-icon">
            <el-icon v-if="!isCollapse" color="#0057FF"><CaretLeft /></el-icon>
            <el-icon v-else color="#0057FF"><CaretRight /></el-icon>
          </div>
        </div>
      </div>
    </div>
    <!-- 右侧内容 -->
    <div class="right-content">
      <router-view v-if="isRouterAlive" v-slot="{ Component }">
        <keep-alive :include="includeList">
          <component :is="Component" :key="$route.name" />
        </keep-alive>
      </router-view>
    </div>
  </div>
</template>

<script setup>
import { onBeforeMount, reactive, toRefs } from "vue";
import leftMenu from "./left-menu.vue";
import api from "@/service/container";

const $router = useRouter();
const $route = useRoute();

const state = reactive({
  isRouterAlive: true,
  isCollapse: false,
  includeList: [],
  loading: false,
  menuData: [
    // {
    //   menuName: "金专",
    //   children: [
    //     {
    //       menuName: "新增专业申请表",
    //       icon: "",
    //       url: "/majorApply"
    //     },
    //     {
    //       menuName: "专业人才培养方案",
    //       icon: ""
    //     },
    //     {
    //       menuName: "专业人才需求调研报告",
    //       icon: ""
    //     }
    //     // {
    //     //   menuName: "能力图谱智能生成",
    //     //   icon: ""
    //     // }
    //   ]
    // }
    /*{
      menuName: "金课",
      children: [
        {
          menuName: "AI金课标准解析（PDF文档）",
          icon: ""
        },
        {
          menuName: "AI数字人智能生成",
          icon: ""
        },
        {
          menuName: "AI课件智能生成（PPT）",
          icon: ""
        },
        {
          menuName: "AI微课智能剪辑",
          icon: ""
        }
      ]
    },
    {
      menuName: "金教材",
      children: [
        {
          menuName: "AI金教材标准解析",
          icon: ""
        },
        {
          menuName: "AI文档智能排版",
          icon: ""
        },
        {
          menuName: "AIGC智能内容生成",
          icon: ""
        },
        {
          menuName: "AI内容智能润色",
          icon: ""
        }
      ]
    }*/
  ]
});
const { isRouterAlive, isCollapse, includeList, loading, menuData } = toRefs(state);

//路由守卫
onBeforeRouteUpdate((to) => {
  // getIncludeList(to);
});
onBeforeMount(() => {
  // 当前路由加入缓存
  let currentRoute = $router.currentRoute.value;
  if (currentRoute.meta.keepAlive) {
    state.includeList.push(currentRoute.name);
  }
  // getMenuData();
});

//获取rouer缓存数据项
const getIncludeList = (val) => {
  if (val.meta.keepAlive && state.includeList.indexOf(val.name) === -1) {
    state.includeList.push(val.name);
  }
};

// 获取菜单树
const getMenuData = () => {
  api
    .getMenu({
      sourceModule: "USER"
    })
    .then((res) => {
      state.menuData = res.data;
    });
};

//菜单伸缩
const telescopingClick = () => {
  state.isCollapse = !state.isCollapse;
};
</script>

<style lang="scss" scoped>
.layout-container {
  width: 100%;
  height: 100%;
  background-image: url("@/assets/images/container/container_bg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: flex;
  .left-side {
    box-sizing: border-box;
    width: 280px;
    height: 100%;
    background-color: #fff;
    position: relative;
    // box-shadow: 0 0 3px 5px rgba($color: #000000, $alpha: 0.1);
    box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.1);
    transition: all 0.6s;
    z-index: 10;
    .left-side-content {
      width: 100%;
      height: 100%;
      overflow: hidden;
      .system-title {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 30px 0;
        .system-logo {
          width: 36px;
          height: 17px;
          transition: all 0.6s;
        }
        .title-text {
          font-family: Alibaba PuHuiTi-Medium;
          font-size: 14px;
          color: #000000;
          white-space: nowrap;
          overflow: hidden;
          transition: all 0.6s;
        }
      }
      .collapse-title {
        .title-text {
          width: 0;
        }
      }
      .noCollapse-title {
        .system-logo {
          margin-right: 8px;
        }
        .title-text {
          width: auto;
        }
      }
    }
    .telescoping-btn {
      box-sizing: border-box;
      width: 14px;
      height: 60px;
      position: absolute;
      right: -14px;
      top: calc(50% - 30px);
      cursor: pointer;
      &::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 120%;
        height: 110%;
        background-color: #000;
        clip-path: polygon(0% 0%, 100% 15%, 100% 85%, 0% 100%);
        filter: blur(8px) opacity(0.1);
        transform: translate(0px, -3px);
        z-index: 0;
      }
      .telescoping-btn-bg {
        width: 14px;
        height: 60px;
        clip-path: polygon(0% 0%, 100% 15%, 100% 85%, 0% 100%);
        background-color: #fff;
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 11px;
      }
    }
  }
  .right-content {
    box-sizing: border-box;
    flex: 1;
    height: 100%;
  }
  :deep(.el-container) {
    position: relative;
  }
}
</style>
